/**
 * 公司名称  : 唐山启奥（Shinow）
 * 项目名称   : oss2016
 * JDK 版本号        : jdk1.6.2
 * 版本号                 : 1.0
 * 创建时间：2016年9月29日 上午10:05:25
 * 创建人：lzy
 **/
package com.shinowit.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shinowit.dao.mapper.InstockInfoMapper;
import com.shinowit.model.InstockInfo;
import com.shinowit.model.MerchandiseTypeInfoCriteria;
import com.shinowit.model.Page;

/**
 * 类说明：入库信息Controller
 * 
 * @author lzy
 * @version Version 1.0
 * @since JDK 1.6
 */
@Controller
@RequestMapping(value = "/instock")
public class InStockController {

	@Autowired
	private InstockInfoMapper instockInfoMapper;

	@RequestMapping(value = "/instock")
	public String viewStock() {
		return "/stock/list";
	}

	@RequestMapping(value = "/instockPage")
	@ResponseBody
	public Page<InstockInfo> getListPage(
			@RequestParam(value = "page", defaultValue = "1") Integer pageIndex,
			@RequestParam(value = "rows", defaultValue = "10") Integer pageSize,
			String typeCode, String typeName, String sort, String order) {
		Map<String, Object> result = new HashMap<String, Object>();

		MerchandiseTypeInfoCriteria ex = new MerchandiseTypeInfoCriteria();
		MerchandiseTypeInfoCriteria.Criteria cr1 = ex.createCriteria();

		if ((null != typeCode) && (typeCode.trim().length() > 0)) {
			cr1.andTypeCodeLike(typeCode + "%");
		}

		if ((null != typeName) && (typeName.trim().length() > 0)) {
			cr1.andTypeNameLike(typeName + "%");
		}

		ex.setPageIndex(pageIndex);
		ex.setPageSize(pageSize);

		if ((null != sort) && (sort.trim().length() > 0)) {
			ex.setOrderByClause(sort);
		}

		if ((null != order) && (order.trim().length() > 0)) {
			if (!"asc".equalsIgnoreCase(order)) {
				ex.setOrderByClause(ex.getOrderByClause() + " desc");
			}
		}

		Page<InstockInfo> page = new Page<InstockInfo>();
		page.setPageNo(pageIndex);
		page.setPageSize(pageSize);
		List<InstockInfo> list = instockInfoMapper.selectByListPage(page);
		page.setResults(list);
		// List<MerchandiseTypeInfo>
		// data_list=merchandise_type_info_dao.selectByExamplePage(ex);
		//
		// result.put("rows", data_list);
		//
		// long record_count=merchandise_type_info_dao.countByExample(ex);
		// result.put("total", record_count);

		return page;
	}

}
